<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1,user-scalable=0" name="viewport">
    <title>线上商城</title>
    <link href="../../public/plugin/weui/weui.min.css" rel="stylesheet">
    <link href="../../public/plugin/jquery-weui/css/jquery-weui.min.css" rel="stylesheet">
    <link href="../../public/plugin/vant/index.css" rel="stylesheet">
    <link href="../../public/css/iconfont.css?v=20210227" rel="stylesheet">
    <link href="../../public/css/store.css?v=20210227" rel="stylesheet">
    <link href="../../public/css/common.css?v=2023060901" rel="stylesheet">
</head>

<style type="text/css">

    .refund_btn {
        width: 25%;
        height: 14%;
        position: absolute;
        bottom: 0;
        right: 10px;
    }

    .cart-item-checkbox {
        height: 100%;
        position: absolute;
        padding: 5px;
    }

    .delete-button {
        height: 100%;
    }

    .cart-item {
        padding-top: 10px;
    }

    .cart-item-checkbox {
        height: 100%;
        position: absolute;
        padding: 5px;
    }

</style>

<body>
<div :style="{ height: pageHeight + 'px' }" id="app" style="overflow-y: auto;" v-cloak>
    <div class="banner" v-show="!showDetail">
        <van-swipe :autoplay="3000" class="my-swipe" indicator-color="white">
            <van-swipe-item v-for="item in bannerList">
                <img :src="item.imgUrl" alt="">
            </van-swipe-item>
        </van-swipe>
    </div>
    <!-- 商品查找搜索框 -->
    <van-sticky v-show="activeTab === 0">
        <van-search placeholder="请输入商品名称" v-model="name"></van-search>
    </van-sticky>
    <!-- 商品区 -->
    <div class="weui-flex" v-show="activeTab === 0 && !showDetail">
        <!-- 商品列表 -->
        <div :style="{ height: pageHeight + 'px' }">
            <van-sidebar v-model="activeIndex">
                <van-sidebar-item :badge="categoryNumber(item)" :title="item"
                                  v-for="item in categoryList">
                </van-sidebar-item>
            </van-sidebar>
        </div>
        <!-- 商品展示区 -->
        <div class="weui-flex__item">
            <van-card
                    :num="item.onlineNumber"
                    :price="item.salePrice"
                    :tag="item.typeName"
                    :thumb="item.picUrls?item.picUrls:img"
                    :title="item.commodityName"
                    @click="viewDetail(item)"
                    v-for="item in dataList"
            ></van-card>
        </div>
        <van-empty description="暂无数据" v-show="dataList.length === 0"></van-empty>
    </div>
    <!-- 商品详细信息区 -->
    <div v-show="activeTab === 0 && showDetail">
        <van-swipe :autoplay="3000" :height="200" class="demo-swipe" indicator-color="white">
            <van-swipe-item
                    v-for="url in (productInfo.picUrls ? productInfo.picUrls.split(',') : [img])">
                <van-image :src="url" fit="contain"></van-image>
            </van-swipe-item>
        </van-swipe>
        <div class="product-info">
            <div class="product-name">
                {{ productInfo.commodityName }}
            </div>
            <div class="product-desc">
                {{ productInfo.remark }}
            </div>
            <div class="product-price">
                {{ getPrice(productInfo) }}
            </div>
            <div class="purchase-quantity">
                <van-row justify="space-between" type="flex">
                    <van-col span="12">购买数量</van-col>
                    <van-col span="12" style="text-align: right;">
                        <van-stepper integer min="1" v-model="quantity"></van-stepper>
                    </van-col>
                </van-row>
            </div>
        </div>
        <div class="order-toolbar">
            <van-row justify="center" type="flex">
                <van-col span="12" style="text-align: center;">
                    <van-button @click="addToCart" block color="linear-gradient(to right, #ffd01e, #ff8917)"
                                type="danger">加入购物车
                    </van-button>
                </van-col>
                <van-col span="12" style="text-align: center;">
                    <van-button @click="buyNow" block color="linear-gradient(to right, #ff6034, #ee0a24)" type="danger">
                        立即购买
                    </van-button>
                </van-col>
            </van-row>
        </div>
        <div @click="showDetail = false;" class="home-btn" v-show="activeTab === 0">
            <img alt="" src="../../public/image/icon/back.svg">
        </div>
    </div>
    <!--  购物车  -->
    <div v-show="activeTab === 1">
        <div class="cart-item" v-for="(item,index) in cartList">
            <van-swipe-cell>
                <van-row justify="center" type="flex">
                    <van-col span="2" style="height: 100%;">
                        <van-checkbox @change="changeCheckbox" class="cart-item-checkbox"
                                      v-model="item.checked">
                        </van-checkbox>
                    </van-col>
                    <van-col span="22">
                        <van-card
                                :desc="item.data.remark"
                                :price="getSalePriceInfo(item.data)"
                                :tag="item.tag"
                                :thumb="getCartItemPicUrl(item)"
                                :title="item.name"
                                currency="">
                            <template #footer>
                                <van-stepper @change="changeNums" integer min="1" v-model="item.nums"></van-stepper>
                            </template>
                        </van-card>
                    </van-col>
                </van-row>
                <template #right>
                    <van-button @click="deleteCartItem(index)" class="delete-button" square text="删除"
                                type="danger">
                    </van-button>
                </template>
            </van-swipe-cell>
        </div>
        <van-radio-group style="margin-top: 10px;" v-model="payWay" v-show="cartList.length > 0">
            <van-cell-group>
                <van-cell @click="switchPayWay('wechat')" clickable title="微信支付">
                    <template #right-icon>
                        <van-radio name="wechat"></van-radio>
                    </template>
                </van-cell>
                <van-cell :title="'积分支付' + ' (当前拥有:' + totalPoints + ')'" @click="switchPayWay('point')"
                          clickable>
                    <template #right-icon>
                        <van-radio name="point"></van-radio>
                    </template>
                </van-cell>
                <van-cell :title="'积分+钱支付' + ' (当前拥有:' + totalPoints +'积分'+ ')'"
                          @click="switchPayWay('pointPlusMoney')"
                          clickable>
                    <template #right-icon>
                        <van-radio name="pointPlusMoney"></van-radio>
                    </template>
                </van-cell>
            </van-cell-group>
        </van-radio-group>
        <!-- 优惠券选择区-->
        <div v-show="cartList.length > 0">
            <van-cell :label="'已优惠'+couponAmount+'元'"
                      :value="couponText"
                      @click="showList=true" is-link
                      title="选择优惠券"
                      v-show="payWay==='wechat'">
            </van-cell>
            <van-popup
                    :style="{ height: '60%' }"
                    closeable
                    position="bottom"
                    round
                    v-model="showList"
            >
                <van-empty description="优惠券空空如也" v-show="usableList.length === 0"></van-empty>
                <div :class="item.couponType===0? 'coupon-blue-gradient':item.couponType===1?'coupon-green-gradient':'coupon-red-gradient'"
                     class="coupon coupon-wave-left coupon-yellow"
                     v-for="item in usableList">
                    <div class="coupon-info coupon-hole coupon-info-right-dashed">
                        <div class="coupon-price"> &yen;{{item.discountAmount}}{{item.couponType === 2 ? '折' : '元'}}
                        </div>
                        <div class="coupon-desc" v-show="item.couponType===0">
                            {{item.templateName}},可直接使用
                        </div>
                        <div class="coupon-desc" v-show="item.couponType===1">
                            {{item.templateName}},满{{item.amountMeet}}元使用
                        </div>
                        <div class="coupon-desc" v-show="item.couponType===2">
                            {{item.templateName}},可直接使用
                        </div>
                        <div class="coupon-expiry-date">有效期：{{getCouponDateRange(item)}}</div>
                    </div>
                    <div @click="checkCoupon(item)" class="coupon-get coupon-get-already">
                        立即使用
                    </div>
                    <div class="coupon-state" v-show="item.check">已选中</div>
                </div>
            </van-popup>
        </div>
        <van-empty description="购物车空空如也" v-show="cartList.length === 0"></van-empty>
        <div @click="activeTab = 0;" class="home-btn" v-show="activeTab === 1">
            <img alt="" src="../../public/image/icon/back.svg">
        </div>
        <van-submit-bar
                :currency="payByWechat ? '￥' : '积分'"
                :label="this.payByPointPlusMoney?'合计:'+plusMoney+'元+':'合计:'"
                :price="getMoney()"
                @submit="handleSubmit"
                button-text="提交订单">
            <van-checkbox @click="checkAll" v-model="allChecked">全选</van-checkbox>
        </van-submit-bar>
    </div>
    <!--  购买历史  -->
    <div v-show="activeTab === 2">
        <div class="sale-list">
            <div class="weui-panel weui-panel_access">
                <div class="weui-panel__bd">
                    <div class="weui-media-box weui-media-box_text"
                         v-for="item in saleList">
                        <h4 class="weui-media-box__title" style="color: #4274c9;font-weight: bold">
                            {{ item.commodityName}}
                        </h4>
                        <!--                        <van-button class="refund_btn" round text="退款" type="danger"></van-button>-->
                        <p class="weui-media-box__desc">{{item.payDate }} </p>
                        <ul aria-hidden="true" class="weui-media-box__info" style="color: #0b7408">
                            <van-image :src=" item.picUrls ? item.picUrls.split(',') : [img]"
                                       style="float: right;"
                                       width="100">
                            </van-image>
                            <li aria-hidden="true" class="weui-media-box__info__meta">
                                <span style="color: #ee0a24;font-weight: bold;">
                                    {{ getSaleAmount(item) }}
                                </span>
                            </li>
                            <li aria-hidden="true" class="weui-media-box__info__meta weui-media-box__info__meta_extra"
                                id="js_p4m1_extra">{{ item.payTypeName }}
                            </li>
                            <li aria-hidden="true" class="weui-media-box__info__meta">{{ item.payStatusName }}</li>
                        </ul>
                        <p class="weui-media-box__desc">{{item.memberName }} </p>
                    </div>
                </div>
            </div>
        </div>
        <van-empty description="暂无数据" v-show="saleList.length === 0"></van-empty>
    </div>
    <!-- 底下选择区 -->
    <van-tabbar @change="handleChangeTabBar" active-color="#3193F2" v-model="activeTab">
        <van-tabbar-item icon="bag">商品</van-tabbar-item>
        <van-tabbar-item :badge="cartList.length" icon="cart">购物车</van-tabbar-item>
        <van-tabbar-item icon="manager">订单</van-tabbar-item>
    </van-tabbar>
</div>
<script src="../../public/plugin/jquery/jquery.min.js" type="text/javascript"></script>
<script src="../../public/plugin/jquery-weui/js/jquery-weui.min.js" type="text/javascript"></script>
<script src="../../public/plugin/vue/vue.min.js" type="text/javascript"></script>
<script src="../../public/plugin/vant/vant.min.js" type="text/javascript"></script>
<script src="../../public/plugin/moment/moment.min.js" type="text/javascript"></script>
<script src="../../public/js/common.js?v=20230615002" type="text/javascript"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            bannerList: [
                {imgUrl: '../../public/image/banner/banner1.png'},
                {imgUrl: '../../public/image/banner/banner2.png'},
                {imgUrl: '../../public/image/banner/banner3.png'}
            ],
            pageHeight: 0,
            activeTab: 0,
            activeIndex: 0,
            quantity: 1,
            couponType: '2',
            showDetail: false,
            allChecked: false,
            showList: false,
            payWay: 'wechat',
            name: '',
            img: 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg',
            commodityId: '',
            cartList: [],
            commodityList: [], //商品信息
            saleList: [], // 购买记录
            usableList: [], // 未使用
            memberInfo: {},
            productInfo: {}
        },
        computed: {
            // 商品分类列表
            categoryList: function () {
                // 先将名字过滤
                let category = Array.from(new Set(this.commodityList.map(function (item) {
                    return item.tabShowName;
                })));
                category.push("全部");
                return category;
            },
            dataList: function () {
                let self = this;
                let category = self.categoryList[self.activeIndex];
                var tmpList = self.commodityList.filter(function (item) {
                    return item.tabShowName === category;
                })
                // 全部
                if (category === "全部") {
                    tmpList = self.commodityList;
                }
                // 输入的名称
                if (self.name) {
                    return tmpList.filter(function (item) {
                        return item.commodityName.indexOf(self.name) > -1;
                    })
                }
                return tmpList;
            },
            changeCheckbox: function () {
                this.allChecked = this.cartList.length > 0 && this.cartList.filter(function (item) {
                    return !item.checked
                }).length === 0
                this.payWay = 'wechat';
            },
            // 是否全为积分兑换商品
            allPayByPointsCartList: function () {
                let tmpList = this.cartList.filter(function (item) {
                    return item.checked && item.data.pointExchange === 0;
                })
                let tmpList2 = this.cartList.filter(function (item) {
                    return item.checked
                })
                return tmpList2.length > 0 && tmpList2.length === tmpList.length;
            },
            // 是否全为积分+钱换购
            allPayByPointPlusMoneyCartList: function () {
                let tmpList = this.cartList.filter(function (item) {
                    return item.checked && item.data.pointPlusExchange === 0;
                })
                let tmpList2 = this.cartList.filter(function (item) {
                    return item.checked
                })
                return tmpList2.length > 0 && tmpList2.length === tmpList.length;
            },
            // 购物车中是否包含两种支付方式的商品
            mixedCartList: function () {
                var tmpList = this.cartList.filter(function (item) {
                    return item.checked && item.data.pointExchange === 1;
                })
                var tmpList2 = this.cartList.filter(function (item) {
                    return item.checked
                })
                return !(tmpList.length === 0 || tmpList.length === tmpList2.length)
            },
            // 累计RT币
            totalPoints: function () {
                return this.memberInfo ? this.memberInfo.totalPoints : 0
            },
            // 支付方式-微信
            payByWechat: function () {
                return this.payWay === 'wechat';
            },
            // 支付方式-积分
            payByPoint: function () {
                return this.payWay === 'point';
            },
            // 支付方式-积分+钱换购
            payByPointPlusMoney: function () {
                return this.payWay === 'pointPlusMoney';
            },
            plusMoney() {
                return this.cartList.filter(function (item) {
                    return item.checked
                }).reduce(function (pre, item) {
                    return pre + (item.plusMoneyCost * item.nums)
                }, 0.00)
            },
            checkedCartList() {
                return this.cartList.filter(function (item) {
                    return item.checked
                })
            },
            totalMoney: function () {
                // 积分兑换
                if (this.payByPoint) {
                    return this.cartList.filter(function (item) {
                        return item.checked
                    }).reduce(function (pre, item) {
                        return pre + (item.point * item.nums)
                    }, 0.00)
                } else if (this.payByPointPlusMoney) {
                    return this.cartList.filter(function (item) {
                        return item.checked
                    }).reduce(function (pre, item) {
                        return pre + (item.point * item.nums)
                    }, 0.00)
                } else {
                    return this.cartList.filter(function (item) {
                        return item.checked
                    }).reduce(function (pre, item) {
                        return pre + (item.price * item.nums)
                    }, 0.00)
                }
            },
            checkCouponList: function () {
                let self = this;
                return self.usableList.filter(function (item) {
                    return item.check;
                })
            },
            // 券优惠金额
            couponAmount: function () {
                let self = this;
                let amount = 0.0;
                let couponList = self.usableList.filter(function (item) {
                    return item.check;
                })
                // 选中券的金额总和
                couponList.forEach(function (item) {
                    // 1. 折扣券在原价上打折(2)
                    if (item.couponType === 2) {
                        // 折扣金额
                        let discountAmount = (parseFloat(self.totalMoney) * parseFloat(item.discountAmount)).toFixed(2);
                        // 原价 - 折扣价 = 优惠价
                        let preAmount = (parseFloat(self.totalMoney) - parseFloat(discountAmount)).toFixed(2)
                        amount = (parseFloat(amount) + (parseFloat(preAmount))).toFixed(2)
                    }
                    // 2. 满减券(1)
                    if (item.couponType === 1) {
                        amount = (parseFloat(amount) + parseFloat(item.discountAmount)).toFixed(2)
                    }
                    // 3. 代金券(0)
                    if (item.couponType === 0) {
                        amount = (parseFloat(amount) + parseFloat(item.discountAmount)).toFixed(2)
                    }
                })
                return amount ? amount : 0;
            },
            couponText: function () {
                if (this.checkCouponList && this.checkCouponList.length > 0) {
                    return '已选中' + this.checkCouponList.length + '张优惠券'
                }
                return '拥有' + this.usableList.length + '张优惠券'
            }
        },
        mounted: function () {
            let self = this;
            self.pageHeight = document.body.clientHeight - 50;
            self.commodityId = getUrlParam("commodityId");

            MemberUtils.getMemberInfo().then(function (res) {
                console.log(res);
                if (res && res.code === 200) {
                    self.memberInfo = res.data;
                    self.getStoreMall();
                    self.getStoreSale();
                    self.getCoupon();
                } else {
                    oAuth2UserInfo();
                }
            });
        },
        methods: {
            getStoreMall: function () {
                let self = this;
                StoreUtils.getStoreMall().then(function (res) {
                    if (res && res.code === 200) {
                        self.commodityList = res.data;
                        if (self.commodityId) {
                            let tmpList = self.commodityList.filter(function (item) {
                                return item.commodityId + '' === self.commodityId + '';
                            });
                            if (tmpList.length === 1) {
                                self.viewDetail(tmpList[0])
                            }
                        }
                    }
                })
            },
            getCoupon: function () {
                let self = this;
                let params = {
                    memberId: self.memberInfo.id,
                }
                MemberUtils.getCouponUsable(params).then(function (res) {
                    console.log(res);
                    if (res && res.code === 200) {
                        self.usableList = res.data.usableList;
                    }
                })
            },
            getStoreSale: function () {
                let self = this;
                StoreUtils.getStoreSale(self.memberInfo.id).then(function (res) {
                    if (res && res.code === 200) {
                        self.saleList = res.data;
                    }
                })
            },
            getCouponDateRange: function (item) {
                return item.startDate.substring(0, 10) + ' 至 ' + moment(item.endDate).subtract(10, 'seconds').format('YYYY-MM-DD');
            },
            handleChangeTabBar: function (active) {
                let self = this;
                self.showDetail = false;
                console.log('handleChangeTabBar');
                self.allUnCheckCoupon();
                if (active === 1) {
                    self.showDetail = true;
                }
                if (active === 2) {
                    // 获取购买记录
                    self.showDetail = true;
                    self.getStoreSale(self.memberInfo.id);
                }
            },
            categoryNumber: function (value) {
                let self = this;
                let number = 0;
                if (value === '全部') {
                    return self.commodityList.length;
                }
                self.commodityList.forEach(function (item) {
                    if (item.tabShowName === value) {
                        number++;
                    }
                })
                return number;
            },
            viewDetail: function (data) {
                let self = this;
                self.productInfo = data;
                self.quantity = 1;
                self.showDetail = true;
            },
            getPrice: function (item) {
                let price = "￥" + item.salePrice + "元";
                return price;
            },
            getSaleAmount: function (item) {
                if (item.payType === 'point') {
                    return "积分:" + item.pointAmount;
                } else if (item.payType === 'wechat') {
                    return "￥" + item.payAmount;
                } else {
                    return item.payAmount + "元+" + item.pointAmount + "积分";
                }
            },
            addToCart: function () {
                // 添加购物车
                let self = this;
                console.log("addToCart");
                // 判断该商品是否已存在
                var exists = false;
                for (var i = 0; i < self.cartList.length; i++) {
                    if (self.cartList[i].id === self.productInfo.commodityId) {
                        exists = true;
                        break;
                    }
                }
                if (!exists) {
                    // 可以积分兑换
                    var pointExchangeAble = self.productInfo.pointExchange === 0;
                    var pointPlusExchangeAble = self.productInfo.pointPlusExchange === 0;
                    self.cartList.push({
                        id: self.productInfo.commodityId,
                        name: self.productInfo.commodityName,
                        nums: self.quantity,
                        type: "goods",
                        tag: pointExchangeAble ? '积分' : '积分+钱',
                        price: self.productInfo.salePrice, // 购买价格
                        amount: self.productInfo.salePrice * self.quantity, // 总金额
                        plusMoneyCost: pointPlusExchangeAble ? self.productInfo.plusMoneyCost : 0, //加钱金额
                        point: self.productInfo.pointCost, // 购买积分
                        data: self.productInfo,
                        checked: true //是否被选中
                    })
                    $.toptip('操作成功', 'success');
                    console.log(self.cartList);
                } else {
                    $.toptip('商品已在购物车', 'success');
                }
            },
            changeCheckbox: function () {
                this.allChecked = this.cartList.length > 0 && this.cartList.filter(function (item) {
                    return !item.checked
                }).length === 0
                this.payWay = 'wechat';
            },
            buyNow: function () {
                console.log("buyNow");
                this.addToCart();
                this.activeTab = 1;
            },
            getCartItemPicUrl: function (item) {
                let self = this;
                if (item.data && item.data.picUrls) {
                    return item.data.picUrls.split(",")[0];
                }
                return self.img;
            },
            deleteCartItem: function (index) {
                this.cartList.splice(index, 1);
            },
            // 切换支付方式
            switchPayWay: function (payWay) {
                console.log('switchPayWay');
                console.log(payWay);
                if (payWay !== 'wechat') {
                    this.allUnCheckCoupon();
                }
                // 判断当前选中的商品是否支持该支付方式
                if (payWay === 'point' && !this.allPayByPointsCartList) {
                    $.toptip('没选中商品或商品中包含无法使用RT币购买的商品！', 'error');
                    this.payWay = 'wechat';
                    return;
                }
                if (payWay === 'pointPlusMoney' && !this.allPayByPointPlusMoneyCartList) {
                    $.toptip('没选中商品或商品中包含无法使用RT币+钱购买的商品！', 'error');
                    this.payWay = 'wechat';
                    return;
                }
                this.payWay = payWay;
            },
            getSalePriceInfo: function (item) {
                let price = "￥" + item.salePrice + "元";
                if (!item.pointPlusExchange && item.pointPlusExchange === 0) {
                    price = "￥" + item.plusMoneyCost + "元" + "+" + item.pointCost + "积分";
                }
                if (!item.pointExchange && item.pointExchange === 0) {
                    price += "或" + item.pointCost + "积分";
                }
                return price;
            },
            checkAll: function () {
                for (var i = 0; i < this.cartList.length; i++) {
                    this.cartList[i].checked = this.allChecked;
                }
                console.log('checkAll');
            },
            // 全部不选中优惠券
            allUnCheckCoupon: function () {
                let self = this;
                self.usableList.forEach(function (item) {
                    item.check = false;
                })
            },
            // 选中优惠券
            checkCoupon: function (data) {
                let self = this;
                if (self.getMoney() === 0 && !data.check) {
                    $.toptip('优惠额度已达到最高！', 'error');
                    return false;
                }
                // 2. 满减券要满足指定金额
                if (data.couponType === 1) {
                    if (self.totalMoney < data.amountMeet) {
                        $.toptip('未达到优惠价使用条件！', 'error');
                        return false;
                    }
                }
                data.check = !data.check
            },
            getMoney: function () {
                let self = this;
                let amount = (parseFloat(self.totalMoney) - parseFloat(self.couponAmount)) * 100;
                return amount > 0 ? amount : 0;
            },
            handleSubmit: function () {
                // 确认支付
                var self = this;
                // 判断选中商品且支付金额大于0
                if (self.cartList.length === 0 || self.totalMoney < 0.01) {
                    $.toptip('请先勾选商品！', 'error');
                    return false;
                }
                if (self.mixedCartList) {
                    $.toptip('兑换商品和普通商品不能一起购买！', 'error');
                    return false;
                }
                // 重新计算每个商品的支付金额
                for (let i = 0; i < self.cartList.length; i++) {
                    self.cartList[i].amount = self.cartList[i].price * self.cartList[i].nums;
                }
                self.$dialog.confirm({
                    title: '支付确认',
                    message: '是否确定支付',
                }).then(function (res) {
                    console.log('confirm');
                    let couponIds = "";
                    let templateIds = "";
                    self.checkCouponList.forEach(function (item) {
                        couponIds += item.id + ","
                        templateIds += item.templateId + ","
                    });
                    couponIds = couponIds.substr(0, couponIds.length - 1);
                    templateIds = templateIds.substr(0, templateIds.length - 1);
                    // 支付参数
                    var payParams = {
                        method: 'store',
                        openid: getCookie(COOKIE_OPENID),
                        params: {
                            paymentType: self.payWay,
                            cartList: self.checkedCartList,
                            operateTime: new Date(),
                            memberId: self.memberInfo.id,
                            amount: self.totalMoney,
                            payAmount: self.getMoney(),
                            point: self.plusMoney, // 消费积分，积分加钱换购时使用
                            couponDiscount: self.couponAmount,
                            couponIds: couponIds,
                            templateIds: templateIds
                        }
                    }
                    console.log(payParams);
                    if (self.payByPoint) {
                        // 积分兑换
                        console.log("积分兑换");
                        payParams.method = 'store';
                    } else {
                        // 现金支付
                        console.log("现金支付");
                        payParams.method = 'store';
                    }
                    console.log(payParams);
                    WXUtils.submitPayOrder(payParams).then(function (res) {
                        console.log(res);
                        if (res && res.code === 200) {
                            console.log("兑换成功！");
                            self.$toast.success('兑换成功！');
                            setTimeout(function () {
                                // 跳转到购物历史，清空购物车
                                self.activeTab = 2;
                                self.handleChangeTabBar(2);
                                self.allUnCheckCoupon();
                                self.getCoupon();
                                self.cartList = [];
                            }, 1000)
                        } else {
                            $.alert(res.msg || '兑换请求失败！');
                        }
                    }).fail(function (err) {
                        $.alert('兑换请求失败！');
                        console.log(err);
                        return false;
                    });
                })

            },
            changeNums: function () {
                let self = this;
                self.allUnCheckCoupon();
            }
        }
    })
</script>
</body>
</html>
